﻿using System.Data;
using System.Data.Odbc;

namespace crm.model
{
    public class OrigemLeadsDao : Conexao
    {
        Conexao c = new Conexao();

        public bool inserir(OrigemLeads obj)
        {
            colParams.Clear();
            string query = "insert into origemleads (nome, fkidstatus) values (?, ?);";
            colParams.Add(new OdbcParameter("@nome", obj.Nome));
            colParams.Add(new OdbcParameter("@fkidstatus", obj.status));
            return c.Executar(query,colParams);
        }

        public DataTable consultar()
        {
            string query = "select * from vw_origemleads";
            return c.ExecutarConsulta(query);
        }

        public DataTable consultar(int id)
        {
            colParams.Clear();
            string query = "select * from origemleads where idorigemleads = ?;";
            colParams.Add(new OdbcParameter("@idorigemleads", id));
            return c.ExecutarConsulta(query,colParams);
        }

        public DataTable consultar(string nome)
        {
            colParams.Clear();
            string query = "select * from origemleads where nomeorigemleads like ? ;";
            colParams.Add(new OdbcParameter("@nome", nome));
            return c.ExecutarConsulta(query,colParams);
        }

        public bool atualizar(OrigemLeads obj)
        {
            colParams.Clear();
            string query = "update origemleads set nome = ? where idorigemleads = ?;";
            colParams.Add(new OdbcParameter("@nome", obj.Nome));
            colParams.Add(new OdbcParameter("@idorigemleads", obj.IdOrigemLeads));

            return c.Executar(query,colParams);
        }

        public bool remover(int id)
        {
            colParams.Clear();
            string query = "update origemleads set fkidstatus = 1 where idorigemleads = ?;";
            colParams.Add(new OdbcParameter("@idorigemleads", id));
            return c.Executar(query,colParams);
        }
    }
}
